package logic

import (
	"context"
	"house_srv/houseclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddHouseLogic {
	return &AddHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddHouseLogic) AddHouse(req *types.AddHouseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.HouseRpc.AddHouse(l.ctx, &houseclient.AddHouseRequest{
		HouseCity:    req.HouseCity,
		HouseAddress: req.HouseAddress,
		HouseBuild:   req.HouseBuild,
		HouseFloor:   req.HouseFloor,
		HouseArea:    int64(req.HouseArea),
		HousePrice:   float32(req.HousePrice),
		HouseAuthor:  req.HouseAuthor,
		HouseStatus:  int64(req.HouseStatus),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "发布成功",
		Code:    200,
		Data:    sms,
	}, nil

}
